# # Created by yang
#
# import time
# from autotest import keyword, checpter
#
#
# @keyword
# def touchByCode(ad,*args,**kwargs):
#     """
#     根据code点击，在wedit界面上code，如：
#     d(resourceId="com.netease.cloudmusic:id/a94", className="android.widget.ImageView", instance=2)
#     :param ad:
#     :param kwargs: 即resourceId="com.netease.cloudmusic:id/a94", className="android.widget.ImageView", instance=2
#     :example:Common.touchByCode(self.ad,resourceId="com.netease.cloudmusic:id/a94", className="android.widget.ImageView", instance=2)
#     :return:
#     """
#     if type(kwargs) is dict and not args:
#         ad(**kwargs).click()
#     else:
#         # 传递的是一个字段串如：
#         # '(resourceId="com.netease.cloudmusic:id/a94", className="android.widget.ImageView", instance=2)'
#         params = args[0].strip()[1:-1]
#         d = {}
#         for item in params.split(","):
#             a,b = item.split("=")
#             d[a.strip()]=eval(b)
#
#         ad(**d).click()
#
#
#
#
# @keyword
# def make_toast(ad, text, duration=1.0):
#     ad.make_toast(text, duration=duration)
#
# @keyword
# def click(ad,x,y):
#     ad.click(x,y)
#
# @keyword
# def wait(ad,n):
#     time.sleep(n)
#
# @keyword
# def wakeScreen(ad):
#     ad.screen_on()
#
# @keyword
# def swipe(ad,sx, sy, ex, ey):
#     ad.swipe(sx, sy, ex, ey)
#
# @keyword
# def freeze_rotation(ad):
#     ad.freeze_rotation(False)
#
# @keyword
# def touchByText(ad, text):
#     """
#     根据文本点击
#     :param ad:
#     :param text:
#     :return:
#     """
#     ad(text=text).click()
#
#
# @keyword
# def touchByDesc(ad, desc):
#     """
#     根据描述点击
#     :param ad:
#     :param desc:
#     :return:
#     """
#     ad(description=desc).click()
#
#
# @keyword
# def launchApp(ad, pkgname, wait=5):
#     """
#     启动app
#     :param ad:
#     :param pkgname: app 包名
#     :param wait: 等待时间
#     :return:
#     """
#     ad.app_start(pkgname)
#     time.sleep(wait) if wait else ""
#
#
# @keyword
# def closeApp(ad, pkgname,wait=1):
#     """
#     停止app
#     :param ad:
#     :param pkgname:
#     :return:
#     """
#     ad.app_stop(pkgname)
#     time.sleep(wait)
#
#
# @keyword
# def touchById(ad, id):
#     """
#     根据id点击
#     :param ad:
#     :param id:
#     :return:
#     """
#     ad(resourceId=id).click()
#
#
# @keyword
# def sendText(ad, text, **kwargs):
#     """
#     点击输入框,输入文本
#     :param ad:
#     :param text: 需输入的文本
#     :param kwargs: 用于定位输入框的参数
#     :return:
#     """
#     ad(**kwargs).set_text(text)
#
#
# @keyword
# def press(ad, key):
#     """
#     按键
#     :param ad:
#     :param key:
#     :return:
#     """
#     ad.press(key)
#
#
# @keyword
# def screenshot(ad):
#     image = ad.screenshot()
#     image.save("home.jpg")
#
#
# @checpter
# def checkIfTextExist(ad, text, expect=True):
#     """
#     检查text是否存在,默认期望存在
#     :param ad:
#     :param text:
#     :param expect: 默认期望存在
#     :return:
#     """
#     return expect == ad(text=text).exists
#
